package com.xiaoshuidi.cloud.module.report.dal.mapper.report;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.xiaoshuidi.cloud.framework.mybatis.core.mapper.BaseMapperX;
import com.xiaoshuidi.cloud.module.report.controller.ajreport.vo.ReportPaymentDetailsReqVO;
import com.xiaoshuidi.cloud.module.report.controller.ajreport.vo.ReportPaymentDetailsRespVO;
import com.xiaoshuidi.cloud.module.report.dal.DO.report.ReportPaymentDetailsDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
@InterceptorIgnore(tenantLine = "true")
public interface ReportPaymentDetailsMapper extends BaseMapperX<ReportPaymentDetailsDO> {


    long countRentDetailsForExport(@Param("req") ReportPaymentDetailsReqVO req);

    List<ReportPaymentDetailsDO> selectRentDetailsForExport(@Param("req") ReportPaymentDetailsReqVO req, @Param("from") Integer from, @Param("pageSize") Integer pageSize);


//    @Select("select * from report_payment_details where handle_flag = 0 and deleted = 0 group by order_id")
    @Select("SELECT s1.* " +
            "FROM report_payment_details s1 " +
            "WHERE s1.id in ( " +
            "    SELECT MAX(id) AS max_id  " +
            "    FROM report_payment_details  " +
            "    WHERE handle_flag = 0 AND deleted = 0 " +
            "    GROUP BY order_id )")
    List<ReportPaymentDetailsDO> selectUnHandle();



    @Update("update report_payment_details set deleted = 1  where order_id = #{orderId} and handle_flag = 1 and deleted = 0")
    void updateRepeatByOrderId(@Param("orderId")Long orderId);



    ReportPaymentDetailsRespVO selectSumAmount(@Param("req") ReportPaymentDetailsReqVO reqVO);
}
